package com.lsongh.springboot2.service;

import com.lsongh.springboot2.entity.Activity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface ActivityService extends JpaRepository<Activity,Integer> {

    @Query("select a from Activity a  where a.actDelete = ?1 order by a.actId desc ")
    List<Activity> findAllAct(Integer isDelete);


    @Query("select a from Activity a  where a.actDelete = ?1 and a.actName  like concat('%' ,?2 , '%')  order by a.actId desc ")
    List<Activity> findAllActByName(Integer isDelete,String name);

    @Modifying(clearAutomatically = true)
    @Transactional
    @Query("update Activity as a set a.actDelete = 1 where a.actId = ?1")
    void deleteActivityById(Integer id);
}
